<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>登录页面</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery.min.js"></script>
    <style>
        body { margin: 0; padding: 0; background: #f5f6fa; }
        .main-wrapper { display: flex; height: 100vh; }
        .left-img { flex: 2; background: url('/img/neumall.png') no-repeat center center; background-size: cover; }
        .right-form { flex: 1; display: flex; align-items: center; justify-content: center; background: #fff; box-shadow: -2px 0 8px rgba(0,0,0,0.03); }
        .form-box { width: 80%; max-width: 320px; }
        .login-title { font-size: 2rem; font-weight: bold; color: #2d3a4b; margin-bottom: 10px; text-align: center; }
        .login-subtitle { font-size: 1rem; color: #888; margin-bottom: 20px; text-align: center; }
        .form-group label { font-weight: 500; }
        .btn-primary { width: 100%; }
        .register-link { display: block; margin-top: 10px; text-align: right; }
        .msg { color: red; margin-top: 10px; text-align: center; }
    </style>
</head>
<body>
<div class="main-wrapper">
    <div class="left-img"></div>
    <div class="right-form">
        <div class="form-box">
            <div class="login-title">NeuMall</div>
            <form id="loginForm" onsubmit="return false;">
                <div class="form-group">
                    <label for="username">账号</label>
                    <input type="text" class="form-control" id="username" name="username" required>
                </div>
                <div class="form-group">
                    <label for="password">密码</label>
                    <input type="password" class="form-control" id="password" name="password" required>
                </div>
                <div class="form-group">
                    <label for="role">身份</label>
                    <select class="form-control" id="role" name="role">
                        <option value="0">患者</option>
                        <option value="1">管理员</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">登录</button>
                <div class="msg" id="msg"></div>
            </form>
            <a href="/register" class="register-link">立即注册</a>
        </div>
    </div>
</div>
<script>
$(function(){
    $('#loginForm').submit(function(){
        var data = {
            username: $('#username').val(),
            password: $('#password').val(),
            role: Number($('#role').val())
        };
        $.ajax({
            url: '/user/login',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function(res){
                if(res.code === 0){
                    if(res.data && res.data.role === 1) {
                        window.location.href = '/adminUserList';
                    } else {
                        window.location.href = '/personalCenter';
                    }
                }else{
                    $('#msg').text(res.message || '登录失败');
                }
            },
            error: function(){
                $('#msg').text('请求失败，请稍后重试');
            }
        });
    });
});
</script>
</body>
</html> 